const { ethers } = require("hardhat");

async function main() {
  // 替换为你的合约地址
  const contractAddress = "0x2145176A4bCEFB4210297A568119Fe3d6BB574e7";
  
  const Greeter = await ethers.getContractFactory("Greeter");
  const greeter = await Greeter.attach(contractAddress);

  // 调用view函数
  console.log("Current greeting:", await greeter.greet());

  // 发送交易修改状态
  const tx = await greeter.setGreeting("New greeting from script!");
  await tx.wait();

  console.log("Updated greeting:", await greeter.greet());
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });